#!/usr/bin/env python
# coding: utf-8

# 准备工作
import requests,json
import pandas as pd
xiaoliu_map = "d8383619b68b944efbd5dfdab977b2ae"

# 地理编码
def geocode(key,address,city):
    geocode_url = "https://restapi.amap.com/v3/geocode/geo?parameters"
    params = {
        "key": key,
        "address": formatted_address,
        "city": city,

    }
    r = requests.get(geocode_url, params=params)
    return r.json()

# 逆地理编码
def re_geocode(location,poitype,radiusextensions):
    re_geocode_url = "https://restapi.amap.com/v3/geocode/regeo?parameters"
    params = {"key": key,
              "location": location,
              "poitype": poitype,
              "radius": radius,
              "extensions": extensions,
            
             }
    r = requests.get(re_geocode_url, params=params)
    return r.json()

# 路径规划
# 函数
def geocode(key,address,city=None):
    """高德api地理编码获取"""
    url = "https://restapi.amap.com/v3/direction/walking?parameters"
    params_geocode = {
    "key": xiaoliu_map,
    "address": address
    
}
    response = requests.get(url=url_geocode,params=params_geocode)
    return response.json()['geocodes'][0]['location']
    return results
# 步行
url = "https://restapi.amap.com/v3/direction/walking?parameters"
params = {
    "key":xiaoliu_map,
    "origin":起始点_中大南方,
    "destination":目的地_龙岗
}
r = requests.get(url,params)
r
#公交车
bus_url = 'https://restapi.amap.com/v3/direction/transit/integrated?parameters'
params = {
        'key':xiaoliu_map,
        'origin':origin,
        'destination':destination,
        'city':'广州'
    }

r = requests.get(bus_url, params=params)
#驾车
car_url = 'https://restapi.amap.com/v3/direction/driving?parameters'
params = {
        'key':xiaoliu_map,
        'origin':"113.679287,23.632575",
        'destination':"113.586605,23.548852",
        'city':'广州'
    }

r = requests.get(car_url, params=params)

#行政区域查询
def districts(keywords):
    inquire_url:"https://restapi.amap.com/v3/config/district?parameters"
    params = {
    
        'key':xiaoliu_map,
        'keywords':keywords,
        'substricts':2
}

    r = requests.get("https://restapi.amap.com/v3/config/district?parameters",params=params)
    results = r.json()
    return results

#搜索POI
def POI(keywords):
    url:"https://restapi.amap.com/v3/place/text?parameters"
    params = {
    
        'key':xiaoliu_map,
        'keywords':keywords,
        "types":types,
        "city":city
}

    r = requests.get("https://restapi.amap.com/v3/place/text?parameters",params=params)
    results = r.json()
    return results

#IP定位
def ip(ip):
    url:"https://restapi.amap.com/v3/ip?parameters"
    params = {
    
        'key':xiaoliu_map,
        'ip':ip
}

    r = requests.get("https://restapi.amap.com/v3/ip?parameters",params=params)
    results = r.json()
    return results

#静态地图
def static(location,zoom):
    url:"https://restapi.amap.com/v3/staticmap?parameters"
    params = {
    
        'key':xiaoliu_map,
        'location':location,
        'zoom':zoom
}

    r = requests.get("https://restapi.amap.com/v3/staticmap?parameters",params=params)
    results = r.json()
    return results

#坐标转换
def transformation(locations):
    url:"https://restapi.amap.com/v3/assistant/coordinate/convert?parameters"
    params = {
        'key':xiaoliu_map,
        'locations':locations,
    }

    r = requests.get("https://restapi.amap.com/v3/assistant/coordinate/convert?parameters",params=params)
    results = r.json()
    return results

#天气查询
def weather(city):
    url:"https://restapi.amap.com/v3/weather/weatherInfo?parameters"
    params = {
    
        'key':xiaoliu_map,
        'city':city
}

    r = requests.get("https://restapi.amap.com/v3/weather/weatherInfo?parameters",params=params)
    results = r.json()
    return results

#输入提示
def tips(keywords,city):
    url:"https://restapi.amap.com/v3/assistant/inputtips?parameters"
    params = {
    
        'key':xiaoliu_map,
        'keywords':keywords,
        'city':city
}

    r = requests.get("https://restapi.amap.com/v3/assistant/inputtips?parameters",params=params)
    results = r.json()
    return results

#交通态势
def traffic(level,rectangle):
    url:"https://restapi.amap.com/v3/traffic/status/rectangle?parameters"
    params = {
    
        'key':xiaoliu_map,
        'level':level,
        'rectangle':rectangle
}

    r = requests.get("https://restapi.amap.com/v3/traffic/status/rectangle?parameters",params=params)
    results = r.json()
    return results
